package com.qfmy.mystation.ui.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.qfmy.mystation.R;
import com.qfmy.mystation.databinding.FragmentWallpaperBinding;

public class WallpaperFragment extends Fragment {
    private FragmentWallpaperBinding binding;

    public static WallpaperFragment newInstance() {
        return new WallpaperFragment();
    }

    @SuppressLint("NonConstantResourceId")
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentWallpaperBinding.inflate(inflater, container, false);
        binding.navBottom.setOnItemSelectedListener(item -> {
            Fragment fragment;
            switch (item.getItemId()) {
                case R.id.nav_live_wallpaper:
                    fragment = new LiveWallpaperFragment();
                    break;
                case R.id.nav_my_wallpaper:
                    fragment = new MyWallpaperFragment();
                    break;
                default:
                    fragment = new StaticWallpaperFragment();
                    break;
            }
            requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fc_wallpaper, fragment).commit();
            return false;
        });
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}